<template>
  <div>
    <el-form-item label="选择流程">
      <el-select v-model="localData.wfCode" clearable filterable>
        <el-option v-for="opt in modelList" :key="opt.dictValue" :label="`${opt.dictLabel}(${opt.dictValue})`" :value="opt.dictValue" />
      </el-select>
    </el-form-item>
    <el-form-item label="实例id绑定属性" label-width="120px">
      <el-cascader
        :props="CascaderProps"
        :options="attrList"
        v-model="localData.bindInstanceId"
        placeholder="请选择属性"
        filterable
        clearable
        :show-all-levels="false"
      >
        <template #default="{ data: opt }">
          <span>{{ `${opt.entityDesc}(${opt.entityName})` }}</span>
        </template>
      </el-cascader>
    </el-form-item>
  </div>
</template>

<script>
export default {
  name: 'FlowableRunImgConfig',
  props: {
    data: {
      type: Object,
      default: () => {}
    },
    attrList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      modelList: [],
      localData: {},
      CascaderProps: {
        value: 'entityName',
        label: 'entityDescName',
        children: 'childList',
        emitPath: false
      },
    };
  },
  watch: {
    data: {
      handler(newVal) {
        if (newVal) {
          this.localData = newVal;
        }
      },
      deep: true,
      immediate: true
    },
    localData: {
      handler(newVal) {
        this.$emit('update:data', newVal);
      },
      deep: true
    }
  },
  mounted() {
    this.getFlowModelList();
  },
  methods: {
    getFlowModelList() {
      return this.getDicts('code_wf_deployment_list').then((response) => {
        this.modelList = response.data;
      });
    }
  }
};
</script>
